package com.e3.basdoc.bank.service;

import java.util.List;

import com.e3.basdoc.bank.model.BankModel;
import com.e3.basdoc.region.service.RegionQueryService;
import com.e3.core.base.ServiceLocator;
import com.e3.core.cache.CacheLoader;

public class BankCacheLoader implements CacheLoader {

	private BankQueryService bankQueryService;

	private RegionQueryService regionQueryService;

	public BankQueryService getBankQueryService() {
		if (bankQueryService == null) {
			bankQueryService = ServiceLocator
					.getQueryService(BankQueryService.class);
		}
		return bankQueryService;
	}

	public RegionQueryService getRegionQueryService() {
		if (regionQueryService == null) {
			regionQueryService = ServiceLocator.getQueryService(RegionQueryService.class);
		}
		return regionQueryService;
	}

	public void loadeData() throws Exception {

		List<BankModel> models = getBankQueryService().getAllBanks();
		if (models == null || models.isEmpty()) {
			return;
		}
		for (BankModel bankModel : models) {
			BankCacheManager.INSTANCE.put(bankModel);
		}

	}

}
